extends CharacterBody3D

signal bat_detect(bat)
signal bat_away(bat)

var battery = null
var auto_charge = true

func _physics_process(delta):
	pass

func get_battery():
	return battery

func set_auto_charge(auto):
	auto_charge = auto

func _on_detect_body_entered(body):
	battery = body
	print("battery [" + battery.name + "] detect")
	$Timer.start()
	bat_detect.emit(body)

func _on_detect_body_exited(body):
	print("battery took away")
	$Timer.stop()
	battery = null
	bat_away.emit(body) # Replace with function body.

func _on_timer_timeout():
	if (!auto_charge):
		return
	if (battery):
		var soc = battery._get_soc()
		if (soc < 100):
			soc = soc + 1
			battery._set_soc(soc)
